#include <glib.h>

typedef struct employee_info_tag {
    gint id;
    gchar *name;
}employee_info_t;

static void _queue_foreach_print_func(gpointer data, gpointer       user_data)
{
    GList *l = NULL;

    l = (GList *)data;
    if(NULL == l) {
        g_print("input param error! \n");
        return;
    }

    g_print("user_data:%s, id:%d, name:%s \n", (gchar *)user_data, 
        ((employee_info_t *)l->data)->id, ((employee_info_t *)l->data)->name);
}

static void _queue_free_func(gpointer data)
{
    GList *l;
    employee_info_t *einfo = NULL;

    l = (GList *)data;
    if(NULL == l) {
        g_print("input param error! \n");
        return;
    }

    einfo = (employee_info_t *)l->data;
    if ( NULL != einfo ) {
        if(NULL != einfo->name) {
            g_free(einfo->name);
        }
        g_free(einfo);
    }

    g_list_free(l);
}

gint main(gint argc, gchar **argv)
{
    GQueue *q = NULL;
    GList *list[3] = {NULL, NULL, NULL};
    employee_info_t *einfo[3] = {NULL, NULL, NULL};

    einfo[0] = g_new0(employee_info_t, 1);
    einfo[1] = g_new0(employee_info_t, 1);
    einfo[2] = g_new0(employee_info_t, 1);

    einfo[0]->id = 1000;
    einfo[0]->name = g_strdup("Jack");
    einfo[1]->id = 1001;
    einfo[1]->name = g_strdup("Pony");
    einfo[2]->id = 1002;
    einfo[2]->name = g_strdup("Robin");

    list[0] = g_list_append(list[0], (gpointer)einfo[0]); // Jack
    list[1] = g_list_append(list[1], (gpointer)einfo[1]); // Pony
    list[2] = g_list_append(list[2], (gpointer)einfo[2]); // Robin

    q = g_queue_new();

    g_queue_push_tail(q, (gpointer)list[0]);
    g_queue_push_tail(q, (gpointer)list[1]);
    g_queue_push_tail(q, (gpointer)list[2]);

    g_queue_foreach(q, _queue_foreach_print_func, "Queue");

    g_queue_free_full(q, _queue_free_func);

    return 0;
}